import React, { useState, useEffect } from 'react'
import { getUserListByType } from '../api/index'
import { WhiteSpace,Card } from 'antd-mobile'
import { withRouter } from 'react-router-dom'
const Header = Card.Header
const Body = Card.Body

function UserList(props) {
    const { type } = props
    const [data, setdata] = useState([])

    useEffect(() => {
        getUserListByType({ type }).then((result) => {
            setdata(result)
        }).catch((err) => {

        });
    }, [type])

    return <div>
        {
            data.map(user => (
                <div key={user._id}>
                    <WhiteSpace />
                    <Card onClick={() => props.history.push(`/chat/${user._id}`)}>
                        <Header
                            // thumb={require(`../../assets/images/${user.header}.png`)}
                            extra={user.username}
                        />
                        <Body>
                            <div>职位: {user.post}</div>
                            {user.company ? <div>公司: {user.company}</div> : null}
                            {user.salary ? <div>月薪: {user.salary}</div> : null}
                            <div>描述: {user.info}</div>
                        </Body>
                    </Card>
                </div>
            ))
        }
    </div>
}
export default withRouter(UserList)